/*
 * @lc app=leetcode.cn id=1089 lang=typescript
 *
 * [1089] 复写零
 */

// @lc code=start
/**
 Do not return anything, modify arr in-place instead.
 */
function duplicateZeros(arr: number[]): void {
    let stack: number[] = [];
    for (let i = arr.length - 1; i >= 0; i--) {
        const element = arr[i];
        if (element === 0) {
            stack.pop();
            stack.unshift(0, 0);
        } else {
            stack.unshift(element);
        }
    }
    arr.splice(0, arr.length, ...stack.slice(0, arr.length));
}
// @lc code=end
